class Stream < ActiveRecord::Base
	belongs_to :entity
	has_many :public_popsicles
	
	validates :entity_id, :presence => true
	after_create :update_entity_with_stream_id
	
	def update_entity_with_stream_id
		Entity.find(self.entity_id).update_attributes(:stream_id => self.id)		
	end
	
	def find_popsicles		
		popsicles_list = []
		
		PublicPopsicle.all.each do |p|
			if p.stream_id == self.entity_id
				popsicles_list << p
			end
		end	
		
		return popsicles_list
	end
end
